#ifndef _EPOLLSERVER_H
#define _EPOLLSERVER_H

#if defined PLATFORM_WINDOWS
#else
#include "server.h"
#include <list>

namespace SocketLib
{
    template<typename _SOCKETSTRUCT>
    class EpollServer : public BaseServer
    {
        public:
        typedef _SOCKETSTRUCT SOCKETSTRUCT;
        public:

        EpollServer(int num = 1024);
        ~EpollServer();

        bool                poll(long aTimeout);
        int                 getClientNum();
        SOCKETSTRUCT*     getSocketBuffer();

        private:
        void            _auxHandlerNewClient(sock);
        void            _handlerAcceptList();
        void            _handlerCloseList();
        void            _handlerEpollEvent(int AOverTime);


        void            _handlerAllRecv();
        void            _handlerAllSend();

        void            _disConnection(SOCKETSTRUCT*);
        void            _handleSocketClose(SOCKETSTRUCT*);

        void            addFDEvent(SOCKETSTRUCT* pSocketFD, uint32_t);
        void            delFDEvent(SOCKETSTRUCT* pSocketFD);
        void            motifyFdEvent(SOCKETSTRUCT*    pSocketFD, uint32_t);

        void            _insertReadable(SOCKETSTRUCT* pSocketFD);
        void            _insertWriteable(SOCKETSTRUCT* pSocketFD);
        private:

        TypePool<SOCKETSTRUCT>  m_socketPoll;

        const static int MAXEVENTNUM = 1024;

        int             m_epollFD;

        int             m_clientNum;
        std::list<SOCKETSTRUCT*>    m_readableList;
        std::list<SOCKETSTRUCT*>    m_writeableList;
    };
}

#include "../src/epollserver.cpp"

#endif

#endif
